#!/bin/bash

# 创建脚本目录
plg_dir="~/.local/lib/wireshark/plugins"
init_script='/usr/share/wireshark/init.lua'

usr=`whoami`
if [ "${usr}" != "root" ] ; then
    echo "you must be root!"
    exit
fi

function uninstall()
{
    sed -i '/sdtp/d' ${init_script} 
    rm -f ${plg_dir}/*.lua 
}

mkdir -p ${plg_dir}
rt=`grep "sdtp\.lua" ${init_script}` 
if [ "$rt" != "" ] ; then
    echo "发现老版本，卸载老版本"
    uninstall
    echo "卸载完成"
fi

echo "开始安装"
cp *.lua ${plg_dir}/

echo "loadfile(USER_DIR..\"/../../.local/lib/wireshark/plugins/sdtp.lua\")" >> ${init_script} 
